#!/usr/bin/env bash

# Web UI 快速测试脚本
# 用于验证调度状态概览改进

set -euo pipefail

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
FRONTEND_DIR="$PROJECT_ROOT/web/frontend"

echo "====================================="
echo " Web UI 调度状态改进测试"
echo "====================================="
echo ""

# 检查前端目录
if [ ! -d "$FRONTEND_DIR" ]; then
    echo "❌ 前端目录不存在: $FRONTEND_DIR"
    exit 1
fi

# 检查 node_modules
if [ ! -d "$FRONTEND_DIR/node_modules" ]; then
    echo "📦 首次运行,正在安装依赖..."
    cd "$FRONTEND_DIR"
    npm install
    echo "✅ 依赖安装完成"
fi

# 启动前端开发服务器
echo ""
echo "🚀 启动前端开发服务器..."
echo "📍 项目目录: $FRONTEND_DIR"
echo ""
echo "🔗 访问地址:"
echo "   http://localhost:5173"
echo ""
echo "📄 测试页面:"
echo "   调度逻辑: http://localhost:5173/#/dispatch-logic"
echo ""
echo "✨ 新增功能:"
echo "   - 储能已充电价显示 (橙色高亮)"
echo "   - 功率/电价/参数分组展示"
echo "   - 响应式布局优化"
echo ""
echo "💡 提示:"
echo "   - 按 Ctrl+C 停止服务器"
echo "   - 前端代码修改后自动热更新"
echo "   - 确保后端服务正在运行 (port 8080)"
echo ""
echo "====================================="
echo ""

cd "$FRONTEND_DIR"
npm run dev
